<div class="dis-Table" id="body-div">
	<div class="border-right" style="width:200px;background-color: #f5f5f5;">
		<div class="treeShowScroll">
			<div id="getAll" class="all-tree" style="cursor:pointer;">
				<i class="fa fa-list-ul" aria-hidden="true" ></i> <span></span>
			</div>
			<div class="search-jstree" >
				<input id="search-jstree-input" style="height: 25px;"/>
				<img class="middle fa fa-search"  src="static/img/search-input_wev8.png">
			</div>
			<div id="carKindjsTree" style="background-color: rgb(245,245,245)!important;"></div>
		</div>
	</div>
	<div class="layui-fluid">
		<div class="layui-card">
			<h5 class="rightTbTitle"><a id="titleBar" style="color:#696a6c;">用户</a></h5>
			<div class="layui-card-body">
				<form id="searchForm" class="searchForm form-inline">
					<input id="treeId" name="parent.id" type="hidden" value="0" />
					<div class="searchDiv positionSpc">
						<div class="form-group pull-left important">
							<span>登录名</span>
							<input name="s01" component-type="input" class="form-control" type="text" value="" maxlength="100" />
						</div>
						<div class="form-group pull-left ">
							<span>姓名</span>
							<input name="s04" component-type="input" class="form-control" type="text" value="" maxlength="100" />
						</div>
						<div class="form-group pull-left ">
							<span>是否允许登录</span>
							<select name="s10" component-type="select" component-id="yes_no" class="form-control">
								<option value=""></option>
							</select>
						</div>
						<div class="form-group pull-left ">
							<span>仅域控登录</span>
							<select name="s13" component-type="select" component-id="yes_no" class="form-control">
								<option value=""></option>
							</select>
						</div>
					</div>
				</form>
				<div id="toolbar" class="toolbar">
					<div class="pull-right">
						<a id="searchBtn" class="btn btn-success btn-bordered btn-sm"><i class="fa fa-search"></i> <font>查询</font></a>
						<a id="resetBtn" class="btn btn-success btn-bordered btn-sm"><i class="fa fa-refresh"></i> <font>重置</font></a>
						<a id="easySearch" class="btn btn-success btn-bordered btn-sm" style="display: none;"><i class="fa fa-backward"></i> <font>返回</font></a>
						<a id="hardSearch" class="btn btn-success btn-bordered btn-sm" style="display: inline-block;"><i class="fa fa-search-plus"></i> <font>高级查询</font></a>
					</div>
				</div>
				<table id="table-list"></table>
			</div>
		</div>
	</div>
</div>

<script>
    layui.use(['common', 'view', 'admin', 'laytpl'], function () {
        var $ = layui.$
            , R = layui.common
            , view = layui.view
            , admin = layui.admin
            , laytpl = layui.laytpl;

        var getTime = "-" + new Date().getTime();
        $("#body-div").attr("id", "body-div" + getTime);
        $("#table-list").attr("id","table-list" + getTime);
        var btnsStr = LayerUtil.getBtnsStrFromMenuData();
		var bootstrapTableUtil = new BootstrapTableUtil(getTime);
		bootstrapTableUtil.init({
			url: admin.basePath + '/dynamic/zform/data?path=path&traceFlag=&formNo=' + 'sys_user',
			method: 'post',
			columns: [
                {
					checkbox: true
				},
				{
					field: 'parent.name',
					title: '归属机构',
					sortable: true,
					sortName: 'a.parent_id',
					
					formatter:function(value, row , index){
						return "<a href='javascript:;' class='view'>" + row.parent.name + "</a>";
					},
					events: {
						'click .view': function (e, value, row, index) {
							viewForm({
								id: row.id
							})
						}
					},
				},
				{
					field: 's01',
					title: '登录名',
					sortable: true,
					sortName: 'a.login_name',
					
				},
				{
					field: 's02',
					title: '用户编号',
					sortable: true,
					sortName: 'a.no',
					
				},
				{
					field: 's04',
					title: '姓名',
					sortable: true,
					sortName: 'a.name',
					
				},
				{
					field: 'g01.name',
					title: '职务',
					sortable: true,
					sortName: 'a.level_id',
					
				},
				{
					field: 's08',
					title: '状态',
					sortable: true,
					sortName: 'a.useable',
					
					formatter:function(value, row , index){
						return myHelper.getValueFromDictionary("sys_useable",value);
					},
				},
				{
					field: 'sort',
					title: '排序',
					sortable: true,
					sortName: 'a.sort',
					
				},
                {
                	title: layui.admin.lang() ? 'Operation' : '操作',
                	width: '45px',
					"class": 'center must',
					events: {
						'click .view': function (e, value, row, index) {
							viewForm({id: row.id})
						},
						'click .edit': function (e, value, row, index) {
							addOrEdit({
								id: row.id
							})
						},
						'click .del': function (e, value, row, index) {
							delFuc(row);
						},
						'click .unlock': function (e, value, row, index) {
							LayerUtil.ajax({
								type: 'post',
				        		url: admin.basePath + '/sys/user/unlockUser?loginName='+row.s01,
				        		success: function(res){
				        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
				        			bootstrapTableUtil.refresh();
				        		}
				        	})
						},
						'click .dataPermission':function(e, value, row, index){
							var obj = {
								id: row.id,
								allData: {
									url: '/sys/tagTree/dataPermissionTree',
									type: 'get'
								},
								detail: {
									url: '/system/datapermission/getPermission?id=' +  row.id,
									type: 'get'
								},
								save: {
									url: '/system/datapermission/savePermission',
									type: 'post'
								},
								isParent: true
							}
							LayerUtil.openZtree(obj,'数据权限');
						}
						
					},
					formatter: function(value, row, index) {
						if(row.s10 == "1"){
							return btnsStr.tableBtnsStr.replace("unlock","unlock btn-hide");
						}
						return btnsStr.tableBtnsStr;
					},
                },
            ]
		},"sys_user");

		$("#body-div"+getTime).find("#addBtn").on("click",function(){
			addOrEdit();
		});

		$("#body-div"+getTime).find("#removeBtn").on("click",function(){
			var ids = bootstrapTableUtil.getMultiId();
			if(ids){
				LayerUtil.confirm(layui.admin.lang() ? "Are you sure?" : "确定删除吗？", function(){
					LayerUtil.ajax({
						type: 'post',
		        		url: admin.basePath + '/dynamic/zform/delete?formNo=sys_user&ids=' + ids,
		        		success: function(res){
		        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
		        			bootstrapTableUtil.refresh();
		        		}
		        	})
				})
	       	}
		});

		function addOrEdit(initData) {
			var id = initData ? initData.id : '';
			LayerUtil.openDialog({
				title : layui.admin.lang() ? 'New ' : '添加用户',
				formLay : 'sys_user',
				initData : initData,
				setDataWidthAjax : true,
				actionDataName : 'data',
				url : 'admin/sys_user/form',
				actionUrl : admin.basePath + '/dynamic/zform/getZform?formNo=sys_user&id=' + id,
	            btn : ['保存', '取消'],
	            btn_EN : ['Save', 'Cancel'],
	            func1 : function(index,layero) {
					var validateForm = $(layero).find("#inputForm").validate({
						rules: {
						    newPsdAgain: {
						      equalTo: "#newPsd"
						    }
						}
					});
					if(validateForm.form()){
						var data = myHelper.composeData($(layero).find("#inputForm"));
						if(data.newPsdAgain){
							data.s03 = data.newPsdAgain;
						}
		            	LayerUtil.ajax({
	                		//url : admin.basePath + '/dynamic/zform/save',
	                		url : admin.basePath + '/sys/user/save',
	                		type : 'post',
	                		data : JSON.stringify(data),
	                		success : function(res) {
	                			LayerUtil.success(res[LayerUtil.getMsgLang()]);
	                			bootstrapTableUtil.refresh();
	                			layui.layer.close(index)
	                		}
	                	});
	               }
	            }
			})
		}

		function viewForm(initData) {
			LayerUtil.openDialogView({
				title : layui.admin.lang() ? 'View ' : '查看用户',
				formLay : 'sys_user',
				initData : initData,
				url : 'admin/sys_user/form',
				actionUrl : admin.basePath + '/dynamic/zform/getZform?formNo=sys_user&id=' + initData.id,
				actionDataName : 'data',
				setDataWidthAjax : true,
				formFunctionData: "view"
			})
		}

		function delFuc(row){
    		LayerUtil.confirm(layui.admin.lang() ? 'Are you sure you want to delete?':'确认要删除吗？', function() {
				LayerUtil.ajax({
					url: admin.basePath + '/dynamic/zform/delete?formNo=sys_user&ids=' + row.id,
					type:'post',
	        		shade:true,
					success: function(res){
	        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
	        			bootstrapTableUtil.refresh();
	        		}
				});
			});
    	}

		//Left tree
		function refresh(node){
			$("#body-div"+getTime).find('#treeId').val(node.id);
			bootstrapTableUtil.refresh();
			var html = layui.admin.lang() ? '/' : '用户/';
			$("#body-div"+getTime).find("#titleBar").html(html+node.text);
		}

		var jsTreeUtil = new JsTreeUtil(getTime,{
			url:admin.basePath + '/dynamic/zform/treeData?formNo=sys_office&parentId&traceFlag=1',
			type: 'post',
			actionDataName: "data"
		});
		jsTreeUtil.init(refresh, layui.admin.lang() ? "All categories": "全部类型", true);

    });
</script>
